window.addEventListener("load", function () {
	// 定个空变量
	let oldSrc = "";
	$("#aplist li").forEach(function (v) {
		// 移入事件
		v.addEventListener("mouseover", function () {
			// 背景颜色和文字颜色改变
			this.style.background = "#2f7ee9";
			this.style.color = "#fff";
			//2-1 先获取到图片里的src路劲
			let imgUrl = this.firstElementChild.src;
			//2-2 动态获取后缀
			let str = imgUrl.slice(imgUrl.lastIndexOf("."));
			// console.log("--", str);
			// 把获取后的节点换成新内容 -c.svg
			this.firstElementChild.src = imgUrl.replace(str, "-c.svg");
			oldSrc = imgUrl; //用之前定义的空变量保存原先路径
		});
		v.addEventListener("mouseout", function () {
			this.style.background = "#fff";
			this.style.color = "#000";
			// 切换成之前的图片
			this.firstElementChild.src = oldSrc;
		});
	});

	//慧集引入效果
	let oldSty = "";
	$(".masterul li").forEach(function (v) {
		v.addEventListener("mouseover", function () {
			//背景颜色
			this.style.background = "#aecfff";
			//字体颜色
			this.style.color = "#0d60d0";
			//发光动画
			this.style.boxShadow = "4px 4px 11px #2f7ee9";
			this.style.transition = "all 0.5s";
		});
		v.addEventListener("mouseout", function () {
			this.style.background = "#fbfbfd";
			this.style.color = "#000";
			this.style.boxShadow = "none";
		});
	});

	//独角区轮播图
	const unicornConts = $(".unicornbox");
	unicornConts[0].style.opacity = "1"; //默认显示第0个
	let index = 1;
	this.window.setInterval(function () {
		//3.排他思想,不管当前谁显示,每一个周期都先让所有消失
		unicornConts.forEach(function (v) {
			console.log(v);
			v.style.opacity = "0";
		});
		//4.通过索引显示对应内容,其他不显示
		unicornConts[index].style.opacity = "1";
		// 5.设置索引变量,每隔一个周期就++
		index++;
		//6.当索引达到最大限度时要回复初始状态
		if (index > unicornConts.length - 1) {
			index = 0;
		}
	}, 3000);

	//广告按钮
	$("#adv div").addEventListener("mouseover", function () {
		this.style.background = "#aecfff";
		this.style.fontSize = "20px";
		this.style.fontWeight = "block";
		this.style.boxShadow = "4px 4px 11px #c7c6c7";
		this.style.transition = "all 0.5s";
	});
	$("#adv div").addEventListener("mouseout", function () {
		this.style.background = "none";
		this.style.fontSize = "14px";
		this.style.fontWeight = "none";

		this.style.boxShadow = "none";
		this.style.transition = "all 0.5s";
	});

	//回到顶部
	window.addEventListener("scroll", function () {
		if (window.scrollY >= 200) {
			$("#back").style.transition = "opacity 1s";
			$("#back").style.opacity = 1;
		} else {
			$("#back").style.opacity = 0;
		}
	});
	$("#back").addEventListener("click", function () {
		window.scrollTo({ left: 0, top: 0, behavior: "smooth" });
	});

	var mySwiper = new Swiper(".swiper", {
		autoplay: true, //可选选项，自动滑动
		pagination: {
			el: ".swiper-pagination",
			clickable: true,
		},
	});
});
